﻿$.fn.smartFloat = function () {
    var position = function (element) {
        var top = element.position().top, pos = element.css("position"), left = element.position().left;
        $(window).scroll(function () {
            var scrolls = $(this).scrollTop();
            var scrollsleft = $(this).scrollLeft();
            if (scrollsleft < left) {
                scrollsleft += left;
            }
            if (scrolls < top) {
                scrolls += top;
            }
            if (window.XMLHttpRequest) {
                element.css({
                    top: scrolls,
                    left: scrollsleft
                });
            }
            else {
                element.css({
                    top: scrolls,
                    left: scrollsleft
                });
            }
        });
    };
    return $(this).each(function () {
        position($(this));
    });
};